package com.bulletelc.apollopre.module.main.center.quotation.detail;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bulletelc.apollopre.R;
import com.bulletelc.apollopre.entity.QuotationBean;
import com.bulletelc.apollopre.manager.imageload.ImageLoaderManager;

import java.util.List;

/**
 * Created by Administrator on 2018/5/17.
 */

public class QuotationDetailAdapter extends BaseAdapter {

    private Context context;
    private List<QuotationBean.ActiveItemsBean> activeItemsBeanList;
    private LayoutInflater inflater;

    public QuotationDetailAdapter(Context context, List<QuotationBean.ActiveItemsBean> activeItemsBeanList) {
        this.context = context;
        this.activeItemsBeanList = activeItemsBeanList;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return activeItemsBeanList.size();
    }

    @Override
    public Object getItem(int i) {
        return activeItemsBeanList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        QuotationBean.ActiveItemsBean activeItems = activeItemsBeanList.get(i);
        ViewHolder viewHolder;
        if (view == null) {
            viewHolder =  new ViewHolder();
            view = inflater.inflate(R.layout.quotation_detail_list_item, viewGroup, false);
            viewHolder.ivCover = view.findViewById(R.id.ivCover);
            viewHolder.tvName = view.findViewById(R.id.tvName);
            viewHolder.tvPrice = view.findViewById(R.id.tvPrice);
            viewHolder.tvSku = view.findViewById(R.id.tvSku);
            viewHolder.tvQuantity = view.findViewById(R.id.tvQuantity);
            viewHolder.tvSubTotalPrice = view.findViewById(R.id.tvSubTotalPrice);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        ImageLoaderManager.getInstance().loadImage(ImageLoaderManager.getDefaultOptions(viewHolder.ivCover, activeItems.getProductImg().getMediumUrl()));
        viewHolder.tvName.setText(activeItems.getProductImg().getName());
        viewHolder.tvPrice.setText("¥" + activeItems.getProduct_price());
        viewHolder.tvSku.setText(activeItems.getSku_label() + "*" + activeItems.getQuantity());
        viewHolder.tvQuantity.setText("数量：" + activeItems.getQuantity());
        viewHolder.tvSubTotalPrice.setText("¥" + activeItems.getSubtotal());
        return view;
    }

    class ViewHolder{
        TextView tvName, tvPrice, tvSku, tvSubTotalPrice, tvQuantity;
        ImageView ivCover;
    }
}
